<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>VueLayers UMD</title>

  <style>
    html, body, #app {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body * {
      box-sizing: border-box;
    }

    #app {
      display: flex;
      flex-direction: column;
    }

    #map {
      flex: 1 1 auto;
    }
  </style>
  <link rel="stylesheet" href="../lib/style.css">
</head>
<body>

  <div id="app">
    <div id="map">
      <vl-map :load-tiles-while-animating="true"
              :load-tiles-while-interacting="true"
              data-projection="EPSG:4326">
        <vl-view :zoom="zoom"
                 :center="center"
                 :max-zoom="maxZoom"
                 :min-zoom="minZoom"
                 :rotation="rotation"></vl-view>

        <vl-layer-tile>
          <vl-source-osm></vl-source-osm>
        </vl-layer-tile>

        <vl-layer-vector>
          <vl-source-vector :features="features"></vl-source-vector>
        </vl-layer-vector>

        <vl-layer-vector>
          <vl-source-vector ident="draw-target"></vl-source-vector>
        </vl-layer-vector>
        <vl-interaction-draw source="draw-target" type="Polygon"></vl-interaction-draw>
        <vl-interaction-snap source="draw-target"></vl-interaction-snap>
        <vl-interaction-modify source="draw-target"></vl-interaction-modify>

      </vl-map>
    </div>
    <div>
      <button @@click="test">test</button>
    </div>
  </div>

  <script src="https://unpkg.com/vue@latest/dist/vue.min.js"></script>
  <script src="../lib/index.umd.js"></script>
  <script>
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      data: {
        center: [37.41, 8.82],
        rotation: 0,
        zoom: 2,
        maxZoom: 18,
        minZoom: 0,
        features: [
          {
            id: 'd45bdba2-84b7-46d9-80a0-64b78c67acd1',
            type: 'Feature',
            geometry: {
              type: 'Point',
              coordinates: [37.41, 15.82],
            },
            properties: {
              name: 'Point 1',
              color: 'yellow',
              value: 100,
            },
          },
          {
            id: 'd45bdba2-84b7-46d9-80a0-64b78c67acd2',
            type: 'Feature',
            geometry: {
              type: 'Point',
              coordinates: [30.41, 10.82],
            },
            properties: {
              name: 'Point 2',
              color: 'yellow',
              value: 50,
            },
          },
          {
            id: 'd45bdba2-84b7-46d9-80a0-64b78c67acd3',
            type: 'Feature',
            geometry: {
              type: 'Point',
              coordinates: [47.41, 15.82],
            },
            properties: {
              name: 'Point 3',
              color: 'yellow',
              value: 0,
            },
          },
        ],
      },
      methods: {
        formatText (f) {
          return `${f.properties.name} ${f.properties.value}%`
        },
        test () {
          setInterval(() => {
            for (let i = 0; i < this.features.length; i++) {
              let color = ['blue', 'yellow', 'green', 'pink'][Math.ceil(Math.random() * 100) % 4]
              let value = Math.ceil(Math.random() * 100)
              this.features[i].properties.color = color
              this.features[i].properties.value = value
            }
          }, 1000)
        },
      },
    })
  </script>
</body>
</html>
